package com.ficus.road.maintain.core.model.coverage;

import com.ficus.road.maintain.core.model.RoadCoverDetail;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Date;

/**
 * @author xiawen yang
 * @date 2022/3/15 下午2:27
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RoadCoverageWeekZH {

    private String roadid;

    private String statistype;

    private String cyclenum;

    private double worklengthall;

    private String managesectionid;

    private double worklength;

    private double coverweek;

    public RoadCoverageWeek convert2RoadCoverage(RoadCoverageWeekZH zh, Date date) {
        RoadCoverDetail.RoadCoverageStatusEnum status = (ObjectUtils.isEmpty(zh.getCoverweek()) || zh.getCoverweek() == 1d)
                ? RoadCoverDetail.RoadCoverageStatusEnum.COVER : RoadCoverDetail.RoadCoverageStatusEnum.UNCOVER;
        return RoadCoverageWeek.builder()
                .id(zh.getRoadid() + zh.getManagesectionid() + zh.getCyclenum())
                .roadId(zh.getRoadid())
                .unitId(zh.getManagesectionid())
                .cycleNum(zh.getCyclenum())
                .cycleCoverage(ObjectUtils.isEmpty(zh.getCoverweek()) ? 0 : zh.getCoverweek())
                .workLength(zh.getWorklength())
                .workLengthAll(zh.getWorklengthall())
                .status(status)
                .lastModificationTime(date)
                .build();
    }
}
